﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebSoftSeo.Models;


namespace WebSoftSeo.Controllers
{
    public class ContactController : Controller
    {
        private WebSoftSeoEntities db = new WebSoftSeoEntities();
        //
        // GET: /Contact/

        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult FormContact(Contact _contact)
        {
            if (ModelState.IsValid)
            {
                _contact.Date = DateTime.Now;
                db.Contacts.Add(_contact);
                db.SaveChanges();
            }
            return RedirectToAction("index", "Home");
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing && (db != null))
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
        public static byte[] encryptData(string data)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] hashedBytes;
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data));
            return hashedBytes;
        }
        public static string md5(string data)
        {
            return BitConverter.ToString(encryptData(data)).Replace("-", "").ToLower();
            //
            // GET: /User/Edit/5
        }
    }
}
